//console.log is there in IE8, but the console object isn't created until you open DevTools. 
if(!window.console) {console={}; console.log = function(){};};
$(function(){
	$.messager.tips = function(msg){
		$.messager.show({
			title:'系统提示',
			msg:msg,
			timeout:3000,
			showType:'slide'
		});
	}
	$.prompt = function(msg,domid){
		var id ="#"+ (domid||"prompt");
		if($(id).size()>0){
			$(id).html(msg);
			$(id).fadeIn('slow');
			setTimeout("$('"+id+"').fadeOut('slow');",3000);
		}else{
			console.log("没有找到dom,id="+id);
		}
	}
	console.log("*程序员");
	console.log("*是电脑灵魂的工程师,");
	console.log("*电脑的一切技能，皆来源于人脑，");
	console.log("*上帝之于人，人之于电脑。");
	console.log("*每一个软件项目，");
	console.log("*都是一个创新。");
	console.log("*本项目开发组成员：胡旭出。");
	console.log(" ------------------------------------------------------------------------------2018年8月21日 0时24分 济南金融干部培训中心");
});
$(function(){
		$('input.easyui-validatebox').validatebox({
			tipOptions: {	// the options to create tooltip
				showEvent: 'mouseenter',
				hideEvent: 'mouseleave',
				showDelay: 0,
				hideDelay: 0,
				zIndex: '',
				onShow: function(){
					if (!$(this).hasClass('validatebox-invalid')){
						if ($(this).tooltip('options').prompt){
							$(this).tooltip('update', $(this).tooltip('options').prompt);
						} else {
							$(this).tooltip('tip').hide();
						}
					} else {
						$(this).tooltip('tip').css({
							color: '#000',
							borderColor: '#CC9933',
							backgroundColor: '#FFFFCC'
						});
					}
				},
				onHide: function(){
					if (!$(this).tooltip('options').prompt){
						$(this).tooltip('destroy');
					}
				}
			}
		}).tooltip({
			position: 'right',
			content: function(){
				var opts = $(this).validatebox('options');
				return opts.prompt;
			},
			onShow: function(){
				$(this).tooltip('tip').css({
					color: '#000',
					borderColor: '#CC9933',
					backgroundColor: '#FFFFCC'
				});
			}
		});
	});
//判断targetSuffix是否在suffixArray范围内
function fileLegalBySuffix(targetSuffix, suffixArray){
	for (var suffix in suffixArray){
		if (suffixArray[suffix] == targetSuffix){
			return true;
		}
	}
	return false;
}
//根据：
//1:文件元素name-fileElemName，
//2.:文件元素id-fileElemId，
//3.:文件元素所在容器id-containerId，
//4.上传的Excel文件的大小（10M以内），
//判断Excel文件是否合法
function checkExcelFile(fileElemName, fileElemId, containerId){
	var filepath = $("input[name='"+fileElemName+"']","#"+containerId).val();    
    var uploadFileSuffix=$("#"+fileElemId).filebox('getText').substr($("#"+fileElemId).filebox('getText').lastIndexOf(".") + 1).toLowerCase();//获得文件后缀名
    var fileSuffixRange = Array("xls","xlsx");
    if (!fileLegalBySuffix(uploadFileSuffix,fileSuffixRange)){
  	  $.messager.alert("提示","上传的不是Excel格式文件！");
  	  return false;
    }
    var file_size = 0;
    var size = 0;
    var browserName = "";
    var isIE = /msie/.test(navigator.userAgent.toLowerCase());//判断是否为IE操作系统，jQuery
    if (isIE) {
    	browserName = "IE";
    	var fileobject = new ActiveXObject ("Scripting.FileSystemObject");//获取上传文件的对象
    	var file = fileobject.GetFile(filepath);//获取上传的文件
    	file_size = file.Size;//检测 上传文件大小
    }else{
    	browserName = "非IE";
    	var file = $("input[name='"+fileElemName+"']","#"+containerId)[0].files[0];
  	  	file_size = file.size;
    }
    if (file_size > 0){
    	size = file_size / 1024 / 1024;
    	console.log("Excel文件大小（MB）：");
    	console.log(size.toFixed(2));
    	if (file_size > 10 * 1024 * 1024){
    		$.messager.alert(browserName + "浏览器提示","当前Excel文件大小：" + size.toFixed(2) + "MB，上传文件不得大于10M！请重新选择！");
    		return false;
    	}
    }
    return true;
}
//根据获取的生命周期判断数据是否有效——true：过期，false：有效
function isExpiredData(val,lifeRange){
	if (null==val){
		return true;
	}
	if (moment().diff(moment(val),'days') > parseInt(lifeRange)){
		return true;
	}    	
	return false;
}

//将过长的title按长度cutlength截成若干行的段，便于显示
function breakTitle(title, cutlength){
	var title_a = title,title_b = "",title_c = "",title_end="";
	if (title.length <= cutlength){
		title_c = title;
	}
	while (title_a.length > cutlength){
		title_b = title_a.slice(0,cutlength);
		title_a = title_a.slice(title_b.length);
		title_c += title_b + "<br>";
		if (title_a.length <= cutlength){
			title_end = title_a;
		}
	}
	if (title_end.length > 0){
		title_c += title_end;
	}
	return title_c;
}

//判断字符串合法性——valStr非空且不为空格——合法：返回空串
function validateNotnull(valStr){
	var retStr = "";
	if ($.trim(valStr).length == 0){
		retStr = "不可为空或空格。";
	}
	return retStr;
}
//判断字符串合法性——valStr长度在valLength以内——合法：返回空串
function validateStrLength(valStr, valLength){
	var retStr = "";
	if (valStr.length > valLength){
		retStr = "长度应该在" + valLength + "字以内。";
	}
	return retStr;
}
//判断数字合法性——valStr为非负整数——合法：返回空串
function validateNNInt(valStr){
	var retStr = "";
	if (valStr.indexOf(".")!=-1 || isNaN(Number(valStr)) || parseInt(valStr, 10)<0){
		retStr = "应为非负整数。";
	}
	return retStr;
}
//判断数字合法性——valStr为非负数（保留2位小数）——合法：返回空串
function validateNNNum(valStr){
	var retStr = "";
	if (isNaN(Number(valStr)) || Number(valStr)<0){
		retStr = "应为非负数（保留2位小数）。";
	}
	return retStr;
}
//判断选择项合法性——选项valStr为非空——合法：返回空串
function validateCombobox(valStr){
	var retStr="";
	if (valStr==""){
		retStr = "选项未选择，请进行选择。";
	}
	return retStr;
}
//客户端一体化合法性校验方法
function validateForSave(arrNotnullTextTitle,arrNotnullTextElems,
		arrTextTitle,arrTextElems,arrTextLength,
		arrNNIntTile,arrNNIntElems,
		arrNNNumTile,arrNNNumElems,
		arrComboboxTitle,arrComboboxElems){
	var retStr = "";
	for (var i=0;i<arrNotnullTextTitle.length;i++){
		var validTest0 = validateNotnull(arrNotnullTextElems[i]);
		if (validTest0!=""){
			retStr += '【' + arrNotnullTextTitle[i] + '】' + validTest0 + '<br>';
		}
	}
	for (var j=0;j<arrTextTitle.length;j++){
		var validTest1 = validateStrLength(arrTextElems[j],arrTextLength[j]);
		if (validTest1!=""){
			retStr += '【' + arrTextTitle[j] + '】' + validTest1 + '<br>';
		}
	}
	for (var k=0;k<arrNNIntTile.length;k++){
		var validTest2 = validateNNInt(arrNNIntElems[k]);
		if (validTest2!=""){
			retStr += '【' + arrNNIntTile[k] + '】' + validTest2 + '<br>';
		}
	}
	for (var l=0;l<arrNNNumTile.length;l++){
		var validTest3 = validateNNNum(arrNNNumElems[l]);
		if (validTest3!=""){
			retStr += '【' + arrNNNumTile[l] + '】' + validTest3 + '<br>';
		}
	}
	for (var m=0;m<arrComboboxTitle.length;m++){
		var validTest4 = validateCombobox(arrComboboxElems[m]);
		if (validTest4!=""){
			retStr += '【' + arrComboboxTitle[m] + '】' + validTest4 + '<br>';
		}
	}
	return retStr;
}

//客户端解析方法——上报标志
function CtoL_reportFlag(code){
	var label = "";
	switch (code){
   		case ('0'):
   			label = "未上报";
   			break;
   		case ('1'):
   			label = "已上报";
   			break;
   		case ('2'):
   			label = "被退回";
   			break;
	}
	return label;
}
//客户端解析方法——报送期数——季度
function CtoL_reportTerm_quarter(code){
	var label = "";
	switch (code){
	case ('01'):
		label = "一季度";
		break;
	case ('02'):
		label = "二季度";
		break;
	case ('03'):
		label = "三季度";
		break;
	case ('04'):
		label = "四季度";
		break;
	}
	return label;
}
//客户端解析方法——报送期数——月份
function CtoL_reportTerm_month(code){
	var label = "月份";
	if (code.length == 2){
		if (code.slice(0,1) == '0'){
			label = code.slice(1) + label;
		}else{
			label = code + label;
		}
	}
	return label;
}
//客户端解析方法——月度对应季度
function month_2_quarter_code(code){
	var label = "";
	switch (code){
	case ('01'):
	case ('02'):
	case ('03'):
		label = "01";
		break;
	case ('04'):
	case ('05'):
	case ('06'):
		label = "02";
		break;
	case ('07'):
	case ('08'):
	case ('09'):
		label = "03";
		break;
	case ('10'):
	case ('11'):
	case ('12'):
		label = "04";
		break;
	}
	return label;
}
//选择当前报送期数
function Sel_currTerm(type, comboboxEle){
	if (type=="quarter"){
		var q = moment().quarter();
		comboboxEle.combobox('setValue',"0"+q.toString());
	}
	if (type=="month"){
		var q = moment().month() + 1;
		var m = q.toString();
		comboboxEle.combobox('setValue',m.length==1 ? "0"+m : m);
	}
}
//客户端解析方法——解析性别
function CtoL_reportGender(code){
	var label = "";
	switch (code){
	case ('1'):
		label = "男";
		break;
	case ('2'):
		label = "女";
		break;
	}
	return label;
}
//客户端解析方法——解析岗位
function CtoL_reportPost(code){
	var label = "";
	switch (code){
	case ('1'):
		label = "柜员";
		break;
	case ('2'):
		label = "管理人员";
		break;
	case ('3'):
		label = "管库员";
		break;
	case ('4'):
		label = "钞票处理";
		break;
	}
	return label;
}
//客户端解析方法——解析机具类型
function CtoL_machineType(code){
	var label = "";
	switch (code){
	case ('1'):
		label = "ATM";
		break;
	case ('2'):
		label = "CRS";
		break;
	case ('3'):
		label = "纸币清分机";
		break;
	case ('4'):
		label = "硬币清分机";
		break;
	case ('5'):
		label = "点钞机";
		break;
	case ('6'):
		label = "纸硬币兑换一体机";
		break;
	case ('7'):
		label = "反假货币工作站";
		break;
	}
	return label;
}
//客户端解析方法——解析工作状态
function CtoL_machineStatus(code){
	var label = "";
	switch (code){
	case ('1'):
		label = "正常";
		break;
	case ('2'):
		label = "维护";
		break;
	case ('3'):
		label = "停用";
		break;
	}
	return label;
}